package com.xigua.chapter_7_Builder.framework;

import java.io.FileNotFoundException;
import java.io.PrintWriter;

/**
 * @author LiRongHua
 * @Title: ${file_name}
 * @Package ${package_name}
 * @Description: ${todo}
 * @date 2022/4/1416:44
 */
public class HtmlBuilder extends Builder {

    public String filename;
    private PrintWriter printWriter;


    public void makeTitle(String title) {
        filename = title+".html";
        try {
            printWriter = new PrintWriter(filename);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
        printWriter.println("<html><head><title>"+title+"</title></head><body>");
        printWriter.println("<h1>"+title+"</h1>");
    }

    public void makeString(String str) {
        printWriter.println("<p>"+str+"</p>");
    }

    public void makeItems(String[] items) {
        printWriter.println("<ul>");
        for (int i = 0; i < items.length; i++) {
            printWriter.println("<li>"+items[i]+"</li>");
        }
        printWriter.println("</ul>");
    }

    public void close() {
        printWriter.println("</body></html>");
        printWriter.close();
    }

    public String getResult(){
        return filename;
    }

}
